<%@page import="java.awt.print.Printable"%>
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<html>
<head>
<meta HTTP-EQUIV="pragma" CONTENT="no-cache">
<meta HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate">
<meta HTTP-EQUIV="expires" CONTENT="0">
<title>_${customer.customerName}_已发货批次</title>


<script type="text/javascript">
		var datatable_content;
		var filterParam={};
		
		 $(function() {
				$("#queryForm").validate();
				var now = new Date();
				var today=(now.getFullYear())+"/"+(now.getMonth()+1)+"/"+(now.getDate());    
				if(!$("#_dataRange").val()){$("#_dataRange").val(today+"-"+today);}
				$("#_dataRange").daterangepicker({format: 'YYYY/MM/DD',dateLimit :{days : 31}});
				//$("#_toDate").datepicker({ format:'yyyy-mm-dd'});
		  });
  
  		function initTable(){
			datatable_content = $("#contentTable").dataTable({
			   "bServerSide":true,
			   "bAutoWidth":false,
	           "sAjaxSource":'${ctx}/workBatch/v2_toSendoutPage',
	           "fnServerData": callback,
	           "fnRowCallback":rowCallBack,
	           "bFilter": false,
	           "bSort": false,
	           "sZeroRecords": "查询无记录！",
	           "bProcessing": true,
	           "oLanguage": {
	               "sUrl": '${ctx}/static/v2/js/plugins/datatables/cn.txt'
	            },
	             "aoColumns":[
	             	 {"mData": null},
	             	 {"mData": 'customer',
	                	 "render": function (obj) {
	                         return obj==null?'':obj.customerName;
	                      }
	                 },
	                 {"mData": 'warehouse',
	                	 "render": function (obj) {
	                         return obj==null?'':obj.groupName;
	                      }
	                 },
	             	 {"mData": "batchCode"},
	             	 {"mData": null},
	             	 {"mData": null},
	             	 {"mData": "orderQty"},
	             	 {"mData": "creater.realname"},
	             	 //{"mData": "fn:substring(createTime,0,19)"},
	             	 {"mData": 'createTime',
                    	 "render": function (obj) {
	                    	  var time=obj.time;
	                         var date = new Date(time);
	                         return date.Format("yyyy-MM-dd hh:mm");
	                      }
                   	 },
	             	 {"mData": null},
	             	 {"mData": null},
	             ],
	             "aoColumnDefs":[
	             	{"aTargets": [4],
		              "mRender": function (data, display, row) {
							return row.pickType == "single" ? "单件":
								   row.pickType == "multi" ? "多件" : "";
			           }
		            },
		            
		            {"aTargets": [5],
		              "mRender": function(data,display,row){
		              		return row.flowType == "prePrint" ? "预先打单":
		              			   row.flowType == "intimePrint" ? "及时打单" : "";
		              }
		            },
		            {"aTargets": [9],
		              "mRender": function(data,display,row){
		              		return row.status == "1" ? "已创建批次":
		              			   row.status == "2" ? "已创建任务":
		              			   row.status == "3" ? "已拣货":
		              			   row.status == "4" ? "已包装":
		              			   row.status == "5" ? "已发货": "";
		           	   }
		            },
		            
		             {"aTargets": [10],
		              "mRender": function(data,display,row){
		              		var rs = "";
		              		if(row.syncStatus == "finish"){
		              			rs += "已推送";
		              		}else{
		              			rs += "<a href='#' role='button'  onclick='toCreateBatch(\""+ row.batchCode +"\")' class='btn btn-primary' >推送</a>";
		              		}
		              		//rs += "<button type=\"button\"  class=\"btn btn-primary\" onclick=\"${ctx}/workBatch/exportExcelGY/${workBatch.batchCode}\">管易</button>";
		              		// <!--<a href="#" role="button"  onclick="sendGoods('${workBatch.batchCode}')"  class="btn btn-primary" >发货</a>
		  			        //<a href="${ctx}/workBatch/exportExcelGY/${workBatch.batchCode}" role="button"  class="btn btn-primary" >管易</a>-->
		              		return rs;
		           	   }
		            },
	             ]
			});
		}
  		function callback(sSource, aoData, fnCallback ) {
  			
		   aoData.push( { "name": "customerCode", "value": $("#_customerCode").val() } );  
		   aoData.push( { "name": "warehouseCode", "value": $("#_warehouseCode").val() } );
		   aoData.push( { "name": "dataRange", "value": $("#_dataRange").val() } );
		   aoData.push( { "name": "expressCompany", "value": $("#_expressCompany").val() } );
		   $.ajax({ 
		       "type": "post",
		       "contentType": "application/json", 
		       "url": sSource,    
		       "dataType": "json",   
		       "data": JSON.stringify(aoData),
		       "success": fnCallback  
		   });
		}
		
		/**
		*创建了行的回调
		*nRow为当前的tr
		*/
		function rowCallBack(nRow, aData, iDisplayIndex, iDisplayIndexFull){
			var iDisplayStart = datatable_content.fnSettings()._iDisplayStart;
			$("td:eq(0)", nRow).html(iDisplayStart+iDisplayIndex+1);
		}
		
	  function exportExcelGY(){
	        $("#queryForm").attr("action","${ctx}/workBatch/exportExcel");
	        $("#queryForm").submit();
	  }
	  
	   function query(){
	    	var customerCode = $("#_customerCode").val();
    	    var warehouseCode = $("#_warehouseCode").val();
      		if(customerCode || warehouseCode){
      			/* $("#queryForm").attr("action","${ctx}/workBatch/v2_toSendoutPage");
	        	$("#queryForm").submit(); */
      			if($("#queryForm").valid()){
    				if (datatable_content) {
    					datatable_content.fnDestroy();
    				}
    				initTable();
    			}
      		}else{
      			jAlert("客户和仓库,请至少选择一个查询条件");
      		}
	  }
	  
	  function exportExcelYHD(){
	        $("#queryForm").attr("action","${ctx}/workBatch/exportExcel");
	        $("#_moban").val("YHD");
	        $("#queryForm").submit();
	  }
	     
      function exportExcelPY(){
      	    var customerCode = $("#_customerCode").val();
    	    var warehouseCode = $("#_warehouseCode").val();
      		if(customerCode || warehouseCode){
      			$("#queryForm").attr("action","${ctx}/workBatch/exportExcel");
	        	$("#_moban").val("PY");
	        	$("#queryForm").submit();
      		}else{
      			jAlert("客户和仓库,请至少选择一个查询条件");
      		}
	        
      }
      function exportExcelQCT(){
	        $("#queryForm").attr("action","${ctx}/workBatch/exportExcel");
	        $("#_moban").val("QCT");
	        $("#queryForm").submit();
      }
      
      function toCreateBatch(batchCode,obj){
	        $.ajax({
				type : 'post',
				url : '${ctx}/workBatch/toCreateBatch',
				data : {
					batchCode : batchCode
				},
				dataType : 'json',
				success : function(data) {
				    var status=data.status;
					if (status == "1") {
						 alert("推送成功！");
					}else {
						alert("推送失败！");
					}
				},
				error : function() {
					alert("网络繁忙，请稍后重试...");
				}
			});
      }
      function sendGoods(batchCode,obj){
	        $.ajax({
				type : 'post',
				url : '${ctx}/workBatch/sendGoods',
				data : {
					batchCode : batchCode
				},
				dataType : 'json',
				success : function(data) {
				    var status=data.status;
					if (status == "1") {
						 alert("发货成功！");
					}else {
						alert("发货失败！");
					}
				},
				error : function() {
					alert("网络繁忙，请稍后重试...");
				}
			});
      }
      
      function  getSendCount(item){
    	  var customerCode = $("#_customerCode").val();
    	  var warehouseCode = $("#_warehouseCode").val();
    	  var dataRange = $("#_dataRange").val();
    	  if(null == warehouseCode || warehouseCode=="")
    	  {
    		  $("#sendCount_tab").html("<tr><td>请选择仓库</td></tr>");
    		  return;
    	  }
		  $.ajax({
				type : 'post',
				url : '${ctx}/sendCount/query',
				data : 'customerCode=' + customerCode + '&warehouseCode=' + warehouseCode + '&dataRange='+dataRange,
				dataType : 'json',
				success : function(data) {
				   if(data.status=="1")
				   {
					   var htmlStr = "<tr><td>快递</td><td>数量</td></tr>";
					   var total_num=0;
					   $.each(data.content,function(i,obj){
						   htmlStr += "<tr><td>"+(obj.express_company==null?"未打印":obj.express_company)+"</td><td>"+ obj.num + "</td></tr>"
						   total_num +=obj.num;
					   });
					   htmlStr += "<tr><td>总计</td><td>"+total_num+"</td></tr>";
					   $("#sendCount_tab").html(htmlStr);
				   }
				   else
				   {
					   $("#sendCount_tab").html("<tr><td>获取信息错误！</td></tr>");
				   }
				},
				error : function() {
					$("#sendCount_tab").html("<tr><td>获取信息错误！</td></tr>");
				}
			});
	  }
      
      function getOrderStatusCount(){
    	  var customerCode = $("#_customerCode").val();
    	  var warehouseCode = $("#_warehouseCode").val();
    	  var dataRange = $("#_dataRange").val();
    	  $.ajax({
				type : 'post',
				url : '${ctx}/sendCount/queryOrderStatusCount',
				data : 'customerCode=' + customerCode + '&warehouseCode=' + warehouseCode + '&dataRange='+dataRange,
				dataType : 'json',
				async:false,
				success : function(data) {
				   if(data.status=="1")
				   {
					   var htmlStr = "<tr><td><b>订单状态</b></td><td><b>数量</b></td></tr>";
					   var total_num=0;
					   $.each(data.content,function(i,obj){
						   htmlStr += "<tr><td>"+obj.status+"</td><td>"+ obj.num + "</td></tr>"
						   total_num +=obj.num;
					   });
					   htmlStr += "<tr><td>总计</td><td>"+total_num+"</td></tr>";
					   $("#orderStatusCount_tab").html(htmlStr);
				   }
				   else
				   {
					   $("#orderStatusCount_tab").html("<tr><td>获取信息错误！</td></tr>");
				   }
				},
				error : function() {
					$("#orderStatusCount_tab").html("<tr><td>获取信息错误！</td></tr>");
				}
			});
      }
      function getRepeatOrder(){
    	  var dataRange = $("#_dataRange").val();
    	  $.ajax({
				type : 'post',
				url : '${ctx}/sendCount/queryRepeatOrder',
				data : 'dataRange='+dataRange,
				dataType : 'json',
				async:false,
				success : function(data) {
				   if(data.status=="1")
				   {
					   var htmlStr = "<tr><td><b>客户订单号</b></td><td><b>数量</b></td></tr>";
					   var total_num=0;
					   $.each(data.content,function(i,obj){
						   htmlStr += "<tr><td>"+obj.customer_ordeno+"</td><td>"+ obj.num + "</td></tr>"
						   total_num +=obj.num;
					   });
					   htmlStr += "<tr><td>总计</td><td>"+total_num+"</td></tr>";
					   $("#repeatOrder_tab").html(htmlStr);
				   }
				   else
				   {
					   $("#repeatOrder_tab").html("<tr><td>获取信息错误！</td></tr>");
				   }
				},
				error : function() {
					$("#repeatOrder_tab").html("<tr><td>获取信息错误！</td></tr>");
				}
			});
      }
      
      function getOrderStatusCount(){
    	  var customerCode = $("#_customerCode").val();
    	  var warehouseCode = $("#_warehouseCode").val();
    	  var dataRange = $("#_dataRange").val();
    	  $.ajax({
				type : 'post',
				url : '${ctx}/sendCount/queryOrderStatusCount',
				data : 'customerCode=' + customerCode + '&warehouseCode=' + warehouseCode + '&dataRange='+dataRange,
				dataType : 'json',
				async:false,
				success : function(data) {
				   if(data.status=="1")
				   {
					   var htmlStr = "<tr><td><b>订单状态</b></td><td><b>数量</b></td></tr>";
					   var total_num=0;
					   $.each(data.content,function(i,obj){
						   htmlStr += "<tr><td>"+obj.status+"</td><td>"+ obj.num + "</td></tr>"
						   total_num +=obj.num;
					   });
					   htmlStr += "<tr><td>总计</td><td>"+total_num+"</td></tr>";
					   $("#orderStatusCount_tab").html(htmlStr);
				   }
				   else
				   {
					   $("#orderStatusCount_tab").html("<tr><td>获取信息错误！</td></tr>");
				   }
				},
				error : function() {
					$("#orderStatusCount_tab").html("<tr><td>获取信息错误！</td></tr>");
				}
			});
      }
</script>
</head>

<body>
<section class="content">
 <!-- 查询条件  start-->
   	<div class="row">
	<div class="col-md-12">

			<!-- Primary box -->
			<div class="box box-solid box-primary" >
			    
				<div class="box-header">
					<i class="fa fa-search"></i>
					<h3 class="box-title">搜索栏</h3>
				</div>
				
				<div class="box-body">
    <form class="form-search" id="queryForm" method="post" action="${ctx}/workBatch/v2_queryWorkBatchSendout" style="margin-top: 10px;">
    <input type="hidden" name="moban" id="_moban" value="">
    	
    	<!-- 第一行 -->
		<div class="form-group row">
		     <div class="col-sm-3">
						<div class="input-textgroup col-sm-12">
							<span class="input-group-text"> 商家名称： </span> 
					 		 	<select class="form-control"  id="_customerCode" name="_customerCode"  value="${param._customerCode}"  >
							        <option value=""></option>
									<c:forEach items="${customerList}" var="customer">
									<option value="${customer.customerCode}"
										  <c:if test="${param._customerCode eq customer.customerCode }">selected=selected</c:if>
										>${customer.customerName}</option>
									</c:forEach>
								</select> 
						</div>
			</div>
		         <div class="col-sm-3">
						<div class="input-textgroup col-sm-12">
						 	<span class="input-group-text">作业仓库：</span>
							<select  name="_warehouseCode"  id="_warehouseCode" class="form-control">
								<option value=""></option>
								<c:forEach items="${warehouseList}" var="w">
								   <option value="${w.groupCode}" 
								   <c:if test="${param._warehouseCode eq w.groupCode }">selected=selected</c:if>
								   >${w.groupName}</option>
							   </c:forEach>
							</select>
			 			</div>
				 </div>
				 
		   <div class="col-sm-3">
				<div class="input-textgroup col-sm-12">
					<span class="input-group-text">快递公司：</span>
					<select  name="_expressCompany"  id="_expressCompany" class="form-control">
						<option value=""></option>
						<c:forEach items="${cmpList}" var="w">
						   <option value="${w.companyCode}" 
						   <c:if test="${param._expressCompany eq w.companyCode }">selected=selected</c:if>
						   >${w.companyName}</option>
					   </c:forEach>
					</select>
				</div>
			</div>
		</div>
		<div class="form-group row">
		   <div class="col-sm-6">
			<div class="input-textgroup col-sm-12">	
				<span class="input-group-text">发货日期：</span>
				<div class="input-group">
				<div class="input-group-addon">
					<i class="fa fa-calendar"></i>
				</div>
			 	<input type="text" name="_dataRange" id="_dataRange"  class="form-control pull-right required" value="${param._dataRange}" />
			 	</div> 
			</div>
		</div>

		<div class="col-sm-6">
			<div class="input-group col-sm-12">
				<button class="btn btn-info" type="button" onclick="query();">搜索</button>
				<a href='#sendCount' onclick='getSendCount()' class='btn btn-primary' role='button' data-toggle='modal' >快递发货数量</a>
				<a class="btn btn-primary"  href="#" onclick="exportExcelPY();return false;">导出发货清单</a>
				<!-- <a href='#orderStatusCount' onclick='getOrderStatusCount()' class='btn btn-primary' role='button' data-toggle='modal' >订单状态统计</a> -->
				<a href='#repeatOrder' onclick='getRepeatOrder()' class='btn btn-primary' role='button' data-toggle='modal' >重复订单</a>
				<a href='#orderStatusCount' onclick='getOrderStatusCount()' class='btn btn-primary' role='button' data-toggle='modal' >订单状态统计</a>
			</div>
		</div>
		</div>
	 </form>
	</div>
	</div>
	</div>
	</div>
	<div class="form-group row">
		<div class="col-md-12">
			<div class="box box-solid box-primary">
				<div class="box-header">
					<i class="fa fa-list"></i>
					<h3 class="box-title">查询结果</h3>
					<div class="box-tools pull-right">
						<button class="btn btn-primary btn-sm" data-widget="collapse" type="button">
							<i class="fa fa-minus"></i>
						</button>
					</div>
				</div>
	<div class="box-body">
	<table id="contentTable" class="table table-striped table-bordered table-condensed">
		<thead><tr>
			    <th>序号</th>
			    <th>商家</th>
			    <th>仓库</th>
			    <th>批次编号</th>
			    <th>拣货类型</th>
			    <th>作业类型</th>
			    <th>订单数量</th>
			    <th>创建人</th>
			    <th>创建时间</th>
			    <th>批次状态</th>
			    <th>操作</th>
			</tr></thead>
		<tbody>
		
		</tbody>
	</table>
	</div>
	</div>
	</div>
	</div>
	<!-- 弹出窗体-快递数量统计 start  -->
	<div id="sendCount" class="modal fade">
		<div class="modal-dialog" style="width: 60%;">
			<div class="modal-content">
			
				<div class="modal-body">
					<div class="box box-solid box-primary">
			      		<div class="box-header"><span class="box-title">快递数量统计</span></div>
						<div class="box-body">
							<table class="table table-striped table-bordered table-condensed" id="sendCount_tab"></table>
						</div>
					</div>
				</div>
				
			</div>	
		</div>
	</div>
	<!-- 弹出窗体-商品详情 end  -->
	
	<!-- 弹出窗体-作业订单统计 start  -->
	<div id="orderStatusCount" class="modal fade">
		<div class="modal-dialog" style="width: 60%;">
			<div class="modal-content">
			
				<div class="modal-body">
					<div class="box box-solid box-primary">
			      		<div class="box-header"><span class="box-title">作业订单统计</span></div>
						<div class="box-body">
							<table class="table table-striped table-bordered table-condensed" id="orderStatusCount_tab"></table>
						</div>
					</div>
				</div>
				
			</div>	
		</div>
	</div>
	<!-- 弹出窗体-作业订单统计 end  -->
	
		<!-- 弹出窗体-重复订单 end  -->
	<div  class="modal  fade"  role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" id="repeatOrder"  >
		 <div class="modal-dialog" style="width:1000">
		
		 
		<div class="modal-content">
		 <div class="modal-header">
			  <h3 id="printerNumber">重复订单</h3>
		  </div>
			
		  <div class="modal-body" style="margin-left: 100px;">
			  <table class="table table-striped table-bordered table-condensed" id="repeatOrder_tab"></table>
		  </div>
			
		
		  </div>
		
		 </div>
	</div>
	<!-- 弹出窗体-重复订单 end  -->
	
	<!-- 弹出窗体-作业订单统计 start  -->
	<div id="orderStatusCount" class="modal fade">
		<div class="modal-dialog" style="width: 60%;">
			<div class="modal-content">
			
				<div class="modal-body">
					<div class="box box-solid box-primary">
			      		<div class="box-header"><span class="box-title">作业订单统计</span></div>
						<div class="box-body">
							<table class="table table-striped table-bordered table-condensed" id="orderStatusCount_tab"></table>
						</div>
					</div>
				</div>
				
			</div>	
		</div>
	</div>
	<!-- 弹出窗体-商品详情 end  -->
	</section>
</body>
</html>
